var currenPage = 1;
var pageSize = 10;
//获取token
//var token=sessionStorage.getItem("token");
var baseUrl = 'http://112.124.20.68:7788/';
//1.请求所有用户角色-设置到搜索下拉框
$.ajax({
    url: baseUrl + "role/findAll",
    type: 'get',
    headers: {
        "Authorization": sessionStorage.getItem("token")
    },
    success: function(data) {
        data.data.forEach((item) => {
            $(".user_container .val").after(`<option>` + item.name + `</option>`);
        });
    }
});
//2.封装请求所有用户数据函数
function findAllByPage(currenPage, pageSize, username, rolename) {
    if (username != '') {
        url = baseUrl + '/baseUser/pageQuery?page=' + currenPage + '&pageSize=' + pageSize + '&username=' + username
    } else if (rolename != '请选择角色') {
        url = baseUrl + '/baseUser/pageQuery?page=' + currenPage + '&pageSize=' + pageSize + '&rolename=' + rolename
    } else if (username != '' && rolename != '请选择角色') {
        url = baseUrl + '/baseUser/pageQuery?page=' + currenPage + '&pageSize=' + pageSize + '&username=' + username + '&rolename=' + rolename
    } else {
        //均为空
        url = baseUrl + '/baseUser/pageQuery?page=' + currenPage + '&pageSize=' + pageSize
    };
    $.ajax({
        url: url,
        type: 'get',
        headers: {
            "Authorization": sessionStorage.getItem("token")
        },
        success: function(data) {
            //根据分页/搜索框查询出来的所有用户数据
            console.log(data, '根据分页/搜索框查询出来的所有用户数据');
            data.data.list.forEach((item) => {
                //插入到表格中
                $('tbody').append(`<tr>
               <td>` + item.id + `</td>;
               <td>` + item.username + `</td>;
               <td>` + item.realname + `</td>;
               <td>` + item.gender + `</td>;
               <td>` + item.status + `</td>;
               <td>` + item.telephone + `</td>;
               <td>
               <span>设置</span>
               <span>移除</span>
               <span>详情</span>
               <span>修改</span> 
               </td>;
                </tr>`);
            });

        }
    });
}